/**
 * $Id$
 *
 */
package com.csoa.community.adapter;

import java.util.List;

import android.content.Context;
import android.os.Parcelable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;

/**
 * @Title: ViewPagerAdapter.java
 * @Copyright: Copyright (c) 2005
 * @Description: <br>
 *               <br>
 * @Created on 2012-2-14 下午04:53:16
 * @author DaiQi
 */
public class ViewPagerAdapter extends PagerAdapter {
    private List<View> mViewList;
    
    public ViewPagerAdapter(Context c,List<View> mViewList) {
        this.mViewList = mViewList;
    }
    
    /* (non-Javadoc)
     * @see android.support.v4.view.PagerAdapter#getCount()
     */
    @Override  
    public int getCount() {  
        return mViewList.size();  
    }  

    /**
     * 从指定的position创建page
     * 
     * @param container
     *            ViewPager容器
     * @param position
     *            The page position to be instantiated.
     * @return 返回指定position的page，这里不需要是一个view，也可以是其他的视图容器.
     */
    @Override
    public Object instantiateItem(View collection, int position) {

        ((ViewPager) collection).addView(mViewList.get(position), 0);

        return mViewList.get(position);
    }

    /**
     * <span style="font-family:'Droid Sans';">从指定的position销毁page</span>
     * 
     * 
     * <span style="font-family:'Droid Sans';">参数同上</span>
     */
    @Override
    public void destroyItem(View collection, int position, Object view) {
        ((ViewPager) collection).removeView(mViewList.get(position));
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == (object);
    }

    @Override
    public void finishUpdate(View arg0) {

    }

    @Override
    public void restoreState(Parcelable arg0, ClassLoader arg1) {

    }

    @Override
    public Parcelable saveState() {
        return null;
    }

    @Override
    public void startUpdate(View arg0) {

    }

}
